import User.User;
import User.people;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class login implements Filter {
    public void destroy() {
    }

    public void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp, javax.servlet.FilterChain chain) throws javax.servlet.ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;

        people people = (people)request.getSession().getAttribute("LOGIN");
        User user=(User)request.getSession().getAttribute("SELF");

        if(request.getRequestURI().contains("/register.jsp")||request.getRequestURI().contains("/login.jsp") || request.getRequestURI().contains("/error.jsp"))
        {
            //response.sendRedirect("https://cas.dgut.edu.cn?appid=javaee&state=STATE");
            chain.doFilter(req, resp);
        }
        else if(people!=null||user!=null)
        {
            chain.doFilter(req,resp);
        }
        else
        {
            response.sendRedirect("/login.jsp");
        }

    }

    public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException {

    }

}
